export default {
  // 默认isDel 1 表示禁用删除，接口以该参数判断，具体根据自定义
  multiDel: function(instance, confirmMsg, ids, sucMsg, errMsg, api, isDel = 1) {
    const id = []
    if (ids) {
      if (typeof ids === 'number') {
        id.unshift(ids)
      } else {
        ids.forEach(row => {
          id.unshift(row.id)
        })
      }
    }
    if (id === false) {
      instance.$message({
        showClose: true,
        message: '请先选择',
        type: 'error'
      })
      return
    }
    const para = {
      id: id,
      is_del: isDel
    }
    instance.$confirm(confirmMsg, {}).then(() => {
      api(para).then(data => {
        if (data.code === 0) {
          instance.$message({
            showClose: true,
            message: data.msg ? data.msg : sucMsg,
            type: 'success'
          })
          instance.getData()
        } else {
          instance.$message({
            showClose: true,
            message: data.msg ? data.msg : errMsg,
            type: 'error'
          })
        }
      })
    })
  },
  // 图片上传
  beforeAvatarUpload: function(instance, file, max_size = 8) {
    const isJPG = file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/gif'
    const isLt2M = file.size / 1024 / 1024 < max_size
    if (!isJPG) {
      instance.$message.error('图片格式有误!')
    }
    if (!isLt2M) {
      instance.$message.error('上传图片大小不能超过 ' + max_size + 'MB!')
    }
    return isJPG && isLt2M
  }
}
